home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 …ember: Reference Library / Dev.CD Dec 96 RL / Dev.CD Dec 96 RL.toast / Technical Documentation / develop / develop Issue 27 / develop Issue 27 code / Internet Config Assistant / toolkit / TEnvironment.cp < prev    next >
Encoding:
Text File  |  1996-06-30  |  5.2 KB  |  241 lines  |  [TEXT/CWIE]

  1. /*
  2.   File:            TEnvironment.cp
  3.  
  4.   Contains:        Information about the software environment
  5.  
  6.   Written by:    Arno Gourdol
  7.  
  8.   Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include "TEnvironment.h"
  13.  
  14. #include <OSUtils.h>
  15. #include <Traps.h>
  16. #include <QDOffscreen.h>
  17. #include <LowMem.h>
  18. #include <Script.h>
  19.  
  20. #include <assert.h>
  21.  
  22.  
  23.  
  24. // --------------------------------------------------------------------
  25. // TEnvironment
  26. // --------------------------------------------------------------------
  27. // Constructor
  28.  
  29. TEnvironment::TEnvironment() :
  30.     fHasColorQuickdraw(triUnknown),
  31.     fHasAppleEvent(triUnknown),
  32.     fHasGestalt(triUnknown),
  33.     fHasExtendedDITL(triUnknown),
  34.     fSystemScriptIsRTL(triUnknown)
  35. {
  36.     fUnimplementedTrapAddress = GetToolTrapAddress(_Unimplemented);
  37.     
  38.     if (!HasGestalt())
  39.     {
  40.         // FatalError();
  41.         assert("Gestalt is required");
  42.     }
  43.  
  44. }
  45.  
  46.  
  47.  
  48. // --------------------------------------------------------------------
  49. // HasGestalt
  50. // --------------------------------------------------------------------
  51. // Returns true if Gestalt is available
  52.  
  53. Boolean TEnvironment::HasGestalt(void)
  54. {
  55.     if (triUnknown == fHasGestalt)
  56.     {
  57.         if (GetOSTrapAddress(_Gestalt) == fUnimplementedTrapAddress)
  58.             fHasGestalt = triFalse;
  59.         else
  60.             fHasGestalt = triTrue;
  61.     }
  62.     
  63.     if (fHasGestalt == triTrue)
  64.         return true;
  65.     else
  66.         return false;
  67. }
  68.  
  69.  
  70.  
  71. // --------------------------------------------------------------------
  72. // HasColorQuickdraw
  73. // --------------------------------------------------------------------
  74. // Returns true if Color Quickdraw if available
  75.  
  76. Boolean TEnvironment::HasColorQuickdraw(void)
  77. {
  78.     if (fHasColorQuickdraw == triUnknown)
  79.     {
  80.         fHasColorQuickdraw = triFalse;
  81.         if (HasGestaltAttribute(gestaltQuickdrawFeatures, gestaltHasColor))
  82.         {
  83.             fHasColorQuickdraw = triTrue;
  84.         }
  85.     }
  86.     
  87.     if (fHasColorQuickdraw == triTrue)
  88.         return true;
  89.     else
  90.         return false;
  91. }
  92.  
  93.  
  94.  
  95. // --------------------------------------------------------------------
  96. // HasAppleEvent
  97. // --------------------------------------------------------------------
  98. // Returns true if AppleEvents are available
  99.  
  100. Boolean TEnvironment::HasAppleEvent(void)
  101. {
  102.     if (fHasAppleEvent == triUnknown)
  103.     {
  104.         fHasAppleEvent = triFalse;
  105.         if (HasGestaltAttribute(gestaltAppleEventsAttr, gestaltAppleEventsPresent))
  106.         {
  107.             fHasAppleEvent = triTrue;
  108.         }
  109.     }
  110.     
  111.     if (fHasAppleEvent == triTrue)
  112.         return true;
  113.     else
  114.         return false;
  115. }
  116.  
  117.  
  118.  
  119. // --------------------------------------------------------------------
  120. // HasExtendedDITL
  121. // --------------------------------------------------------------------
  122. // Returns true if Extended DITLs are available (AppendDITL...)
  123.  
  124. Boolean TEnvironment::HasExtendedDITL(void)
  125. {
  126.     if (fHasExtendedDITL == triUnknown)
  127.     {
  128.         fHasExtendedDITL = triFalse;
  129.         if (HasGestaltAttribute(gestaltDITLExtAttr, gestaltDITLExtPresent))
  130.         {
  131.             fHasExtendedDITL = triTrue;
  132.         }
  133.     }
  134.     
  135.     if (fHasExtendedDITL == triTrue)
  136.         return true;
  137.     else
  138.         return false;
  139. }
  140.  
  141.  
  142.  
  143. // --------------------------------------------------------------------
  144. // GetMonitorRect
  145. // --------------------------------------------------------------------
  146. // Returns the rectangle of the monitor which contains most of r
  147.  
  148. void TEnvironment::GetMonitorRect(const CRect& r, CRect& monitor)
  149. {
  150.  
  151.     if (!HasColorQuickdraw())
  152.     {
  153.         monitor = qd.screenBits.bounds;
  154.         monitor.SetTop(monitor.Top() + LMGetMBarHeight());
  155.         monitor.SetRight(monitor.Right() - 65);     // Leaves room for icons    
  156.     }
  157.     else
  158.     {
  159.         GDHandle bestDevice;
  160.         long bestArea;
  161.         long area;
  162.         GDHandle device;
  163.         Rect intersection;
  164.         Rect deviceRect;
  165.  
  166.         device = GetDeviceList();
  167.         bestArea = 0;
  168.         bestDevice = NULL;
  169.  
  170.         while (device != NULL)
  171.         {
  172.             if (TestDeviceAttribute(device, screenDevice) && TestDeviceAttribute(device, screenActive))
  173.             {
  174.                 deviceRect = (**device).gdRect;
  175.                 if (SectRect(r, &deviceRect, &intersection))
  176.                 {
  177.                     area = (intersection.right - intersection.left) * (intersection.bottom - intersection.top);
  178.                     if (area > bestArea)
  179.                     {
  180.                         bestDevice = device;
  181.                         bestArea = area;
  182.                     }
  183.                 }
  184.             }
  185.             device = GetNextDevice(device);
  186.         }
  187.  
  188.         monitor = (**bestDevice).gdRect;
  189.  
  190.         if (bestDevice == GetMainDevice())
  191.         {
  192.             monitor.SetTop(monitor.Top() + LMGetMBarHeight());
  193.             monitor.SetRight(monitor.Right() - 65);     // Leaves room for icons    
  194.         }
  195.     }
  196. }
  197.  
  198.  
  199.  
  200. // --------------------------------------------------------------------
  201. // GetMainScreenRect
  202. // --------------------------------------------------------------------
  203. // Returns the bounds of the main monitor
  204.  
  205. void TEnvironment::GetMainScreenRect(CRect& theMainScreenRect)
  206. {
  207.     if (HasColorQuickdraw())
  208.     {
  209.         GDHandle theGDHand = LMGetMainDevice();
  210.         theMainScreenRect = (**theGDHand).gdRect;
  211.     }
  212.     else
  213.         theMainScreenRect = LMGetWMgrPort()->portRect;
  214.  
  215.     theMainScreenRect.SetTop(theMainScreenRect.Top() + LMGetMBarHeight());
  216. }
  217.  
  218.  
  219.  
  220. // --------------------------------------------------------------------
  221. // IsSystemScriptRTL
  222. // --------------------------------------------------------------------
  223. // Returns true if the system script is right to left 
  224.  
  225. Boolean TEnvironment::IsSystemScriptRTL(void)
  226. {
  227.     if (fSystemScriptIsRTL == triUnknown)
  228.     {
  229.         fSystemScriptIsRTL = triFalse;
  230.         if (::GetScriptVariable(smSystemScript, smScriptRight) != 0)
  231.         {
  232.             fSystemScriptIsRTL = triTrue;
  233.         }
  234.     }
  235.     
  236.     if (fSystemScriptIsRTL == triTrue)
  237.         return true;
  238.     else
  239.         return false;
  240. }
  241.